<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="8" >
            <a-form-model-item label="时间" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="date">
              <g-year-picker
                placeholder="请选择时间"
                v-model="model.date"
              ></g-year-picker>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="classess">
              <j-dict-select-tag type="list" v-model="model.classess" dictCode="RESEARCEH_XSLW_CLASSESS" placeholder="请选择级别"  @change="getTotalScore"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="总分" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="totalScore">
              <a-input v-model="model.totalScore" placeholder="请输入总分" :disabled="true"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="转载" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="reprint">
              <j-dict-select-tag type="list" v-model="model.reprint" dictCode="RESEARCEH_XSLW_REPRINT" placeholder="请选择是否转载"  @change="getTotalScore"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="16" >
            <a-form-model-item label="收录级别/类型" v-show="model.reprint == '1'" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }" prop="inclusion">
              <a-cascader
                v-model="inclusionTemp"
                :options="options"
                expand-trigger="hover"
                placeholder="Please select"
                @change="getTotalScore"
              />
<!--              :display-render="displayRender"-->
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="论文题目" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }" prop="projectName">
              <a-input v-model="model.projectName" placeholder="请输入论文题目" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" >
            <a-form-model-item label="备注" :labelCol="{ span: 2 }" :wrapperCol="{ span: 22 }" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注" ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
      <!-- 子表单区域 -->
    <research-member-list ref="memberListRef" v-model="memberListTable.dataSource" :project-info="model"  :disabled="formDisabled" :loading="memberListTable.loading"></research-member-list>
  </a-spin>
</template>

<script>

import { getAction } from '@/api/manage'
import { GfxyResearchMemberListMixin } from '@/mixins/GfxyResearchMemberListMixin'
import GYearPicker from '@views/gfxy/common/GYearPicker'
import researchMemberList from '@views/gfxy/common/researchMemberList'

export default {
  name: 'ResearchXslwForm',
  mixins: [GfxyResearchMemberListMixin],
  components: {
    GYearPicker, researchMemberList
  },
  data() {
    return {
      inclusionTemp:[0,0],
      // model:{
      //   inclusion:0
      // },
      options: [
        {
          value: 1,
          label: 'SCI、EI、SSCI',
          children: [
            {
              value: 11,
              label: '收录',
              children: [],
            },
          ],
        },
        {
          value: 2,
          label: 'CSCD、CSSCI、新华文摘、中国人民大学复印报刊资料',
          children: [
            {
              value: 21,
              label: '全文发表',
              children: [],
            },
            {
              value: 22,
              label: '论文摘录',
              children: [],
            },
            {
              value: 23,
              label: '篇目索引',
              children: [],
            },
          ],
        },
        {
          value: 3,
          label: 'AHCI、ISSHP、中国社会科学文摘',
          children: [
            {
              value: 31,
              label: '全文收录',
              children: [],
            },
            {
              value: 32,
              label: '论文摘录',
              children: [],
            },
            {
              value: 33,
              label: '篇目索引',
              children: [],
            },
          ],
        },
        {
          value: 4,
          label: 'ISTP、ISR、MR、PA、CA、BA、SA、CBST',
          children: [
            {
              value: 41,
              label: '全文收录',
              children: [],
            },
            {
              value: 42,
              label: '论文摘录',
              children: [],
            },
            {
              value: 43,
              label: '篇目索引',
              children: [],
            },
          ],
        },
      ],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        labelCol2: {
          xs: { span: 24 },
          sm: { span: 3 },
        },
        wrapperCol2: {
          xs: { span: 24 },
          sm: { span: 20 },
        },
        validatorRules: {
           date: [
              { required: true, message: '请输入时间!'},
           ],
           classess: [
              { required: true, message: '请输入级别!'},
           ],
           projectName: [
              { required: true, message: '请输入论文题目!'},
           ],
          reprint: [
              { required: true, message: '请选择是否转载!'},
          ],

          inclusion: [
            { required: false, message: '请选择是否转载!'},
          ],
        },
        url: {
          add: "/research/researchXslw/add",
          edit: "/research/researchXslw/edit",
          queryById: "/research/researchXslw/queryById",
          getTotalScore: "/research/researchXslw/getTotalScore",
        }
      }
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      projectType:{
        type: Number,
        required: true,
      },
      date:{
        type: String,
        required: true,
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
  updated() {
    this.createTemp()
  },
  methods: {
      // handleOk(){
      //   new Promise((resolve, reject) => {
      //     (this.model.reprint == 1 && this.model.inclusion == 0) ? resolve() : reject(obj)
      //   }).then(()=>{
      //     GfxyResearchMemberListMixin.handleOk()
      //   }).catch((msg)=>{
      //     console.log("转载校验失败： " + msg)
      //     this.validateError(msg)
      //     return false;
      //   })
      // },
      createTemp(){
        this.inclusionTemp[1] = this.model.inclusion
        this.inclusionTemp[0] = parseInt(this.inclusionTemp[1] / 10)
      },
      getTotalScore(){
        let that = this;
        if (this.model.reprint == 1){
          this.validatorRules.inclusion[0].required = true
        }else {
          this.validatorRules.inclusion[0].required = false
        }
        if(this.model.classess != undefined && this.model.reprint != undefined){
          this.confirmLoading = true;
          let inclusionTemp = this.inclusionTemp[1]
          getAction(this.url.getTotalScore,{classess: this.model.classess,reprint:this.model.reprint,inclusion: inclusionTemp}).then((res) => {
            if (res.success) {
              this.model.totalScore = res.result;
              this.model.inclusion = inclusionTemp
              this.$nextTick(()=>{
                this.$refs.memberListRef.getScore();
              })
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
          }).catch(()=>{
            this.$message.warning("出错！");
          }).finally(() => {
            this.confirmLoading = false;
          })
        }
      },
    }
  }
</script>

<style scoped>
</style>